<template>
	<view id="echart-container">
		<view class="charts-box">
			<qiun-data-charts type="column" :chartData="chartData" canvas2d="true" />
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			all: Number,
			wip: Number,
			ip: Number,
			nodeList: Array
		},
		name: "question-echart",
		watch: {
			nodeList: {
				handler(val, oldval) {
					if (JSON.stringify(val) !== JSON.stringify(oldval)) {
						// if (val.length > 0) {
						// 	this.beforeInit();
						// } else {
						// 	this.mixinDatacomLoading = true;
						// 	this._clearChart();
						// 	this.showchart = false;
						// 	this.mixinDatacomErrorMessage = null;
						// }
						this.chartData = this.getData()
						console.log(this.getData())
					}
				},
				immediate: false,
				deep: true
			}
		},
		created() {
			console.log('组件初始化完成');
			this.chartData = this.getData()
		},
		beforeMount() {
			console.log('准备开始挂在页面元素');
			this.chartData = this.getData()
		},
		mounted() {
			console.log('组件挂在完成');
			this.chartData = this.getData()

		},
		methods: {
			getData() {
				if (this.nodeList.length != 0) {
					let x = []
					let wip = []
					let ip = []
					for (let i = 0; i < this.nodeList.length; i++) {
						x.push(this.nodeList[i].name)
						wip.push(this.nodeList[i].notPassCount)
						ip.push(this.nodeList[i].passCount)
					}
					let data = {
						categories: x,
						series: [{
							name: "待整改",
							data: wip,
						}, {
							name: "已整改",
							data: ip
						}]
					}
					return data
				}
			}
		},
		data() {
			return {
				chartData: {}
			};
		}
	}
</script>

<style lang="scss" scoped>
	#echart-container {
		background-color: #FFFFFF;
		height: 460rpx;
		// display: flex;
		// flex-direction: column;
		// justify-content: center;
		// align-items: center;
		border-radius: 20rpx;
		border: 1rpx solid #efefef;



		/* 请根据需求修改图表容器尺寸，如果父容器没有高度图表则会显示异常 */
		.charts-box {
			margin-top: 40rpx;
			width: 100%;
			height: 300rpx;
		}
	}
</style>
